iT邦幫忙

2021 iThome 鐵人賽

DAY 22
0
  • 新增團購訊息
    add 關鍵字 訊息
  • 刪除團購訊息
    刪除 關鍵字
  • 查詢團購訊息
    團購
  • 手動新增團購者
    關鍵字 @Display_name +1
  • 手動刪除團購者
    關鍵字 刪除 @Display_name

手動刪除團購者

手動新增團購者跟手動刪除團購者

if(event.message.text[:event.message.text.find(" "):] in keywords and len(event.message.text)>event.message.text.find(" ")):
    text=event.message.text
    lastLength=text.find(" ")
    if(text[lastLength+1:lastLength+2:]=='@'):            
        key=text[:lastLength:]
        name=text[lastLength+2:text.find(" ",lastLength+1):]
        uid=""
        if not event.message.mention is None:
            for user in event.message.mention.mentionees:
                uid=user.user_id
        quantity=text[text.find(" ",lastLength+1)+1:len(text):]
        cursor=conn.cursor()
        cursor.execute(f"DO $do$ BEGIN IF EXISTS(SELECT uid FROM group_buying_user WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}') AND uid='{uid}' ) THEN UPDATE group_buying_user SET name='{name}',quantity='{quantity}' WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}') AND uid='{uid}'; ELSE INSERT INTO group_buying_user (mid ,uid ,name, quantity) VALUES ((SELECT mid FROM group_buying_message WHERE keyword='{key}'),'{uid}','{name}','{quantity}'); END IF; END $do$")
        conn.commit()
        message=text
        message=TextSendMessage(message)

    elif(text[lastLength+1:text.find(" ",lastLength+1):]=="刪除" and text[text.find(" ",lastLength+1)+1:text.find(" ",lastLength+1)+2:]=='@'):
        if not event.message.mention is None:
            for user in event.message.mention.mentionees:
                uid=user.user_id
        cursor=conn.cursor()
        cursor.execute(f"DELETE FROM group_buying_user WHERE uid='{uid}'")
        conn.commit()
        message=TextSendMessage("從"+text[:event.message.text.find(" "):]+"中移除"+text[text.find(" ",lastLength+1)+2:len(text):])

    else:
        key=text[:lastLength:]
        profile = line_bot_api.get_profile(event.source.user_id)
        cursor=conn.cursor()
        cursor.execute(f"DO $do$ BEGIN IF EXISTS(SELECT uid FROM group_buying_user WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}') AND uid='{profile.user_id}' ) THEN UPDATE group_buying_user SET name='{profile.display_name}',quantity='{text[lastLength+1::]}' WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}' AND uid='{profile.user_id}'); ELSE INSERT INTO group_buying_user (mid, uid, name, quantity) VALUES ((SELECT mid FROM group_buying_message WHERE keyword='{key}'),'{profile.user_id}','{profile.display_name}','{text[lastLength+1::]}'); END IF; END $do$")
        conn.commit()
        message=key+" "+profile.display_name+" "+text[lastLength+1::]
        message=TextSendMessage(message)
    line_bot_api.reply_message(event.reply_token,message)

權限

group_right:
aid|uid|add_message_right|delete_message_right|view_right|add_buyer_right|delete_buyer_right|allow_changeright_right
---|---

cursor.execute(f"SELECT add_message_right,delete_message_right,view_right,add_buyer_right,delete_buyer_right,allow_changeright_right FROM group_right WHERE uid='{event.source.user_id}';")
rows = cursor.fetchone()
  • 新增團購訊息https://ithelp.ithome.com.tw/upload/images/20211004/20140165RRj0xvCTm6.png
  • 刪除團購訊息https://ithelp.ithome.com.tw/upload/images/20211004/20140165i0ynWOUqfs.png
  • 查詢團購訊息https://ithelp.ithome.com.tw/upload/images/20211004/20140165dAkTqjllZl.png
  • 手動新增團購者https://ithelp.ithome.com.tw/upload/images/20211004/20140165jIXlv7aolq.png
  • 手動刪除團購者https://ithelp.ithome.com.tw/upload/images/20211004/20140165Ix7DrCoBVP.png

上一篇
DAY 21 新增查詢與刪除團購訊息
下一篇
DAY 23 為管理者添加管理權限
系列文
LINE Messaging API SDK for Python 實現群組團購輔助機器人30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言